<!-- 供应商画像 -->
<template>
  <div class="">
    <div class="header-box">
      <div class="header-logo">
        <img src="@/assets/img/company-logo.png" alt="">
      </div>
      <div class="header-info">
        <div class="title">河南盛世机械工具集团有限公司</div>
        <div class="tag-box">
          <div v-for="(item, index) in tagList" :key="index" class="tag">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <div class="detail-info-box">
      <transition name="modal-fade">
        <div v-if="isShowDetail" class="detail-info-item">
          <div class="item-box">
            <div class="item"><span>准入时间</span>：<span>2024-04-12</span></div>
            <div class="item"><span>法定代表人</span>：<span>杨先生</span></div>
            <div class="item"><span>联系地址</span>：<span>广州市黄埔区丰乐北路20号</span></div>
          </div>
          <div class="item-box">
            <div class="item"><span>公司性质</span>：<span>民营</span></div>
            <div class="item"><span>公司分类</span>：<span>服务商</span></div>
            <div class="item"><span>经营范围</span>：<span>软件和信息技术服务</span></div>
          </div>
          <div class="item-box">
            <div class="item"><span>广本业务负责人</span>：<span>陈先生</span></div>
            <div class="item"><span>联系电话</span>：<span>139****1234</span></div>
            <div class="item"><span>电子邮件</span>：<span>508041569@abc.com</span></div>
          </div>
        </div>
      </transition>
      <div class="detail-show-btn" @click="isShowDetail = !isShowDetail">
        <span v-show="isShowDetail">收起<a-icon type="up" /></span>
        <span v-show="!isShowDetail">展开<a-icon type="down" /></span>
      </div>
    </div>
    <div class="content-box">
      <div class="shadow-effect">
        <a-card title="合作情况">
          <div class="cor-box">
            <div v-for="(item, index) in corList" :key="index" class="cor-item">
              <div class="item-left">
                <div class="text1">{{ item.text1 }}</div>
                <div class="text2">{{ item.text2 }}</div>
              </div>
              <div class="item-right">
                <div class="text3">{{ item.text3 }}</div>
                <div class="text4">{{ item.text4 }}</div>
              </div>
            </div>
          </div>
        </a-card>
      </div>
      <div class="chart-container">
        <div class="container-item wid-50 shadow-effect">
          <div id="chart1"></div>
        </div>
        <div class="container-item wid-50 shadow-effect">
          <div id="chart2"></div>
        </div>
      </div>
      <a-card title="供应商活跃度" class="mt-10 shadow-effect">
        <div id="chart3"></div>
      </a-card>
      <div class="chart-container">
        <div class="wid-65 shadow-effect">
          <a-card title="风险分析">
            <div class="risk-box">
              <div class="risk-left">
                <a-form-model layout="inline">
                  <a-form-model-item label="">
                    <a-range-picker
                      v-model="createTime"
                      format="YYYY-MM-DD"
                      style="width:100%;"
                      @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                  </a-form-model-item>
                </a-form-model>
                <div id="chart4"></div>
              </div>
              <div class="risk-right">
                <div class="right-header">
                  风险评级：低风险（2.6）
                </div>
                <div class="right-content">
                  <div class="title">核心风险：</div>
                  <div class="text">财务风险：资产负债率82%，短期偿债压力大。</div>
                  <div class="text">地缘政治风险：主要工厂位于贸易摩擦敏感地区。</div>
                  <div class="text">交付稳定性：华南地区物流延迟率较高（15%）。</div>
                  <div class="text">合规风险：尚未通过ISO 14001认证。</div>

                  <div class="title mt-10">应对方针：</div>
                  <div class="text">短期：协商延长付款周期，降低订单依赖至50%。</div>
                  <div class="text">长期：评估东南亚备选供应商，6个月内完成切换测试。</div>
                </div>
              </div>
            </div>
          </a-card>
        </div>
        <div class="wid-35 shadow-effect">
          <a-card title="能力情况">
            <div class="ability-box">
              <div id="chart5"></div>
              <div class="text-box">
                <ul>
                  <li>技术创新：拥有20项核心专利，年研发投入占比12%。</li>
                  <li>成本控制：同类产品单价低于市场均价8%。</li>
                </ul>
              </div>
            </div>
          </a-card>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Chart } from '@antv/g2';

export default {
  name: 'SupplierPortrait',
  components: {
  },
  data() {
    return {
      tagList: [
        { name: 'A类' },
        { name: '软件和信息技术服务业' },
        { name: '供应链' },
        { name: '软件服务' },
        { name: '供应链软件服务' },
        { name: '技术咨询服务' },
        { name: '制造软件服务' },
        { name: '工业软件' },
      ],
      isShowDetail: true,
      corList: [
        { text1: '绩效动态评分', text2: '98分(A)', text3: '多于30%', text4: '供应同行' },
        { text1: '投标年限', text2: '5', text3: '多于30%', text4: '供应同行' },
        { text1: '累计投标次数', text2: '30', text3: '多于30%', text4: '供应同行' },
        { text1: '累计中标次数', text2: '50次', text3: '多于30%', text4: '供应同行' },
        { text1: '累计中标金额', text2: '2,060万', text3: '多于30%', text4: '供应同行' },
        { text1: '近1年签订合同次数', text2: '46次', text3: '多于30%', text4: '供应同行' },
        { text1: '近1年签订合同金额', text2: '1060万', text3: '多于30%', text4: '供应同行' },
        { text1: '累计邀请招标次数', text2: '68次', text3: '多于30%', text4: '供应同行' },
        { text1: '售后操作记录', text2: '5', text3: '多于30%', text4: '供应同行' },
        { text1: '投诉记录', text2: '1', text3: '多于30%', text4: '供应同行' },
      ],

      createTime: [],
      createTimeStart: '',
      createTimeEnd: '',
      
      chartData1: [
        { name: '开口合同', year: '2019', number: 100 },
        { name: '开口合同', year: '2020', number: 140 },
        { name: '开口合同', year: '2021', number: 120 },
        { name: '开口合同', year: '2022', number: 100 },
        { name: '开口合同', year: '2023', number: 40 },
        { name: '闭口合同', year: '2019', number: 70 },
        { name: '闭口合同', year: '2020', number: 60 },
        { name: '闭口合同', year: '2021', number: 135 },
        { name: '闭口合同', year: '2022', number: 115 },
        { name: '闭口合同', year: '2023', number: 15 },
        { name: '协议合同', year: '2019', number: 58 },
        { name: '协议合同', year: '2020', number: 58 },
        { name: '协议合同', year: '2021', number: 40 },
        { name: '协议合同', year: '2022', number: 32 },
        { name: '协议合同', year: '2023', number: 32 },
      ],
      chartData2: [
        { name: '开口合同', year: '2019', number: 1000 },
        { name: '开口合同', year: '2020', number: 1400 },
        { name: '开口合同', year: '2021', number: 1200 },
        { name: '开口合同', year: '2022', number: 1000 },
        { name: '开口合同', year: '2023', number: 450 },
      ],
      chartData3: [
        { name: '投标数', month: '1月', number: 100 },
        { name: '投标数', month: '2月', number: 140 },
        { name: '投标数', month: '3月', number: 230 },
        { name: '投标数', month: '4月', number: 100 },
        { name: '投标数', month: '5月', number: 130 },
        { name: '投标数', month: '6月', number: 225 },
        { name: '投标数', month: '7月', number: 124 },
        { name: '投标数', month: '8月', number: 158 },
        { name: '投标数', month: '9月', number: 138 },
        { name: '投标数', month: '10月', number: 153 },
        { name: '投标数', month: '11月', number: 225 },
        { name: '投标数', month: '12月', number: 225 },
        { name: '中标数', month: '1月', number: 80 },
        { name: '中标数', month: '2月', number: 100 },
        { name: '中标数', month: '3月', number: 200 },
        { name: '中标数', month: '4月', number: 80 },
        { name: '中标数', month: '5月', number: 100 },
        { name: '中标数', month: '6月', number: 180 },
        { name: '中标数', month: '7月', number: 120 },
        { name: '中标数', month: '8月', number: 130 },
        { name: '中标数', month: '9月', number: 100 },
        { name: '中标数', month: '10月', number: 115 },
        { name: '中标数', month: '11月', number: 208 },
        { name: '中标数', month: '12月', number: 192 },
      ],
      chartData4: [
        { x: 2.5, y: 2.5 }
      ],
      chartData5: [
        { label: '质量能力', value: 97 },
        { label: '技术能力', value: 97 },
        { label: '服务能力', value: 84 },
        { label: '成本能力', value: 96 },
        { label: '交付能力', value: 100 },
      ]
    };
  },
  mounted() {
    this.initChart1();
    this.initChart2();
    this.initChart3();
    this.initChart4();
    this.initChart5();
  },
  methods: {
    // 范围日期处理
    setTimeRange(startTimeName, endTimeName, timeRange, timeStringRange) {
      if (timeStringRange.length > 0) {
        const [one, two] = timeStringRange;
        this[startTimeName] = one + ' ' + '00:00:00';
        this[endTimeName] = two + ' ' + '23:59:59';
      } else {
        this[startTimeName] = '';
        this[endTimeName] = '';
      }
    },
    initChart1() {
      const chart = new Chart({
        container: 'chart1',
        autoFit: true,
        height: 300,
        marginRight: 50,
        marginLeft: 50,
      });

      chart.options({
        type: 'interval',
        style: {
          // columnWidthRatio: 1 // 配置柱状图宽度占比
          minWidth: 20,
          maxWidth: 30
        },
        title: {
          title: '年度合同数趋势',
          align: 'center',
          titleFontSize: 16
        },
        data: this.chartData1,
        encode: {
          x: { type: 'field', value: 'year' },
          y: { type: 'field', value: 'number' },
          color: { type: 'field', value: 'name' },
        },
        scale: {
          color: { range: ['#2478F2', '#84B7F9', '#5F9CF8'] },
        },
        legend: {
          color: {
            itemMarker: 'rect',
            itemMarkerSize: 16,
            layout: {
              justifyContent: 'center',
            },
            crossPadding: 30, // Legend 组件和图表的距离（默认为 12）
          },
        },
        transform: [{ type: 'dodgeX' }],
        axis: {
          x: {
            title: false, // 关闭标题或设置标题内容
            line: true, // 是否显示轴线
            grid: false, // 是否显示网格线
          },
          y: {
            title: false, // 关闭标题或设置标题内容
            line: false, // 是否显示轴线
            grid: true, // 是否显示网格线
            gridLineWidth: 1, // 网格线宽度
            gridLineDash: [0, 0], // 实线
          }
        }
      });

      chart.render();
    },
    initChart2() {
      const chart = new Chart({
        container: 'chart2',
        autoFit: true,
        height: 300,
        marginRight: 50,
        marginLeft: 50,
      });

      chart.options({
        type: 'interval',
        style: {
          // columnWidthRatio: 1 // 配置柱状图宽度占比
          minWidth: 20,
          maxWidth: 50
        },
        title: {
          title: '年度合同数趋势',
          align: 'center',
          titleFontSize: 16
        },
        data: this.chartData2,
        encode: {
          x: { type: 'field', value: 'year' },
          y: { type: 'field', value: 'number' },
          color: { type: 'field', value: '#2478F2' },
        },
        legend: {
          color: {
            itemMarker: 'rect',
            itemMarkerSize: 16,
            layout: {
              justifyContent: 'center',
            },
            crossPadding: 30, // Legend 组件和图表的距离（默认为 12）
          },
        },
        axis: {
          x: {
            title: false, // 关闭标题或设置标题内容
            line: true, // 是否显示轴线
            grid: false, // 是否显示网格线
          },
          y: {
            title: false, // 关闭标题或设置标题内容
            line: false, // 是否显示轴线
            grid: true, // 是否显示网格线
            gridLineWidth: 1, // 网格线宽度
            gridLineDash: [0, 0], // 实线
          }
        }
      });

      chart.render();
    },
    initChart3() {
      const chart = new Chart({
        container: 'chart3',
        autoFit: true,
        height: 300,
      });

      chart.options({
        type: 'interval',
        style: {
          // columnWidthRatio: 1 // 配置柱状图宽度占比
          maxWidth: 20
        },
        title: {
          title: '年度合同数趋势',
          align: 'center',
          titleFontSize: 16
        },
        data: this.chartData3,
        encode: {
          x: { type: 'field', value: 'month' },
          y: { type: 'field', value: 'number' },
          color: { type: 'field', value: 'name' },
        },
        scale: {
          color: { range: ['#2478F2', '#68BBC4'] },
        },
        legend: {
          color: {
            itemMarker: 'rect',
            itemMarkerSize: 16,
            layout: {
              justifyContent: 'center',
            },
            crossPadding: 30, // Legend 组件和图表的距离（默认为 12）
          },
        },
        transform: [{ type: 'dodgeX' }],
        axis: {
          x: {
            title: false, // 关闭标题或设置标题内容
            line: true, // 是否显示轴线
            grid: false, // 是否显示网格线
          },
          y: {
            title: false, // 关闭标题或设置标题内容
            line: false, // 是否显示轴线
            grid: true, // 是否显示网格线
            gridLineWidth: 1, // 网格线宽度
            gridLineDash: [0, 0], // 实线
          }
        }
      });

      chart.render();
    },
    initChart4() {
      const chart = new Chart({
        container: 'chart4',
        autoFit: true,
        height: 300,
      });

      chart.options({
        type: 'point',
        style: {
          fill: '#86C9D0',
          stroke: false,
          cursor: 'pointer',
        },
        title: {
          title: '风险评估矩阵',
          align: 'center',
          titleFontSize: 16
        },
        data: this.chartData4,
        encode: {
          x: { type: 'field', value: 'x' },
          y: { type: 'field', value: 'y' },
          size: 6,
        },
        scale: {
          x: { domain: [0, 10], nice: true },
          y: { domain: [0, 10], nice: true },
        },
        axis: {
          x: {
            title: false, // 关闭标题或设置标题内容
            line: true, // 是否显示轴线
            grid: true, // 是否显示网格线
            gridLineWidth: 1, // 网格线宽度
            gridLineDash: [0, 0], // 实线
          },
          y: {
            title: false, // 关闭标题或设置标题内容
            line: true, // 是否显示轴线
            grid: true, // 是否显示网格线
            gridLineWidth: 1, // 网格线宽度
            gridLineDash: [0, 0], // 实线
          }
        }
      });

      chart.render();
    },
    initChart5() {
      const chart = new Chart({
        container: 'chart5',
        autoFit: true,
        height: 250,
      });

      chart.options({
        coordinate: {
          type: 'polar',
        },
        data: this.chartData5,
        children: [
          {
            type: 'line',
            style: {
              zIndex: 0,
              lineWidth: 2,
              lineJoin: 'round',
            },
            encode: {
              x: { type: 'field', value: 'label' },
              y: { type: 'field', value: 'value' },
            },
            scale: {
              x: { padding: 0.5, align: 0 },
              y: { domainMin: 0, domainMax: 100 },
            },
            axis: {
              x: {
                title: false, // 关闭标题或设置标题内容
                grid: false, // 是否显示网格线
                gridLineWidth: 1, // 网格线宽度
                gridLineDash: [0, 0], // 实线
                tick: false, // 是否显示刻度
                labelFontSize: 14,
              },
              y: {
                title: false, // 关闭标题或设置标题内容
                gridConnect: 'line',
                gridLineWidth: 1, // 网格线宽度
                gridLineDash: [0, 0], // 实线
                label: false, // 是否显示刻度值
                gridAreaFill: 'rgba(0, 0, 0, 0.04)',
              }
            },
            tooltip: null
          },
          {
            type: 'point',
            style: {
              fill: '#2478F2',
              stroke: false,
              cursor: 'pointer',
            },
            encode: {
              x: { type: 'field', value: 'label' },
              y: { type: 'field', value: 'value', shape: 'point' },
              size: 3,
              tooltip: null
            }
          }
        ]
      });

      chart.render();
    },
  }
}
</script>

<style lang="less" scoped>
/* 定义模态框淡入淡出的过渡效果 */
.modal-fade-enter-active, .modal-fade-leave-active {
  transition: opacity 0.2s;
}
/* 进入过渡的起始状态 */
.modal-fade-enter, .modal-fade-leave-to {
  opacity: 0;
}

.header-box {
  display: flex;
  background-color: #fff;
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.15);
  padding: 30px;

  position: relative;
  z-index: 2;
  .header-logo {
    flex: 0 0 auto;
    width: 95px;
    height: 72px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .header-info {
    flex: 1 1 auto;
    margin-left: 30px;
    .title {
      color: rgba(0, 0, 0, 1);
      font-size: 24px;
      font-family: Arial-regular;
    }
    .tag-box {
      margin-top: 10px;
      display: flex;
      flex-wrap: wrap;
      .tag {
        border-radius: 4px;
        color: #1890FF;
        font-size: 12px;
        text-align: center;
        border: 1px solid rgba(38, 93, 184, 0.5);
        padding: 0 8px;
        margin: 0 10px 10px 0;
      }
    }
  }
}
.detail-info-box {
  position: relative;
  margin: 0 10px 40px;
}
.detail-info-item {
  display: flex;
  justify-content: space-between;

  border-radius: 4px;
  background-color: rgba(245, 246, 248, 1);
  color: rgba(16, 16, 16, 1);
  font-size: 14px;

  padding: 20px;
  .item-box {
    width: 33%;
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
  }
  .item {
    line-height: 26px;
  }
}
.detail-show-btn {
  position: absolute;
  left: 0;
  bottom: -30px;

  height: 30px;
  line-height: 30px;
  border-radius: 0px 0px 4px 4px;
  background-color: rgba(245, 246, 248, 1);
  text-align: center;

  padding: 0 10px;
  cursor: pointer;
}

.content-box {
  background-color: rgba(245,246,248,1);
  padding: 10px;
}

.cor-box {
  display: flex;
  flex-wrap: wrap;
  .cor-item {
    display: flex;
    width: calc((100% - 60px) / 4);
    border-radius: 4px 4px 4px 4px;
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
    border: 1px solid rgba(187, 187, 187, 1);
    padding: 10px 0;
    margin: 20px 20px 0 0;
    .item-left {
      flex: 1 1 auto;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      .text1 {
        color: rgba(108, 108, 108, 1);
        font-size: 16px;
      }
      .text2 {
        color: rgb(16, 16, 16);
        font-size: 24px;
      }
    }
    .item-right {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      border-left: 1px solid rgba(187,187,187,1);
      padding: 0 10px;
      .text3 {
        color: rgba(0, 0, 0, 1);
      }
      .text4 {
        color: rgba(108, 108, 108, 1);
        margin-top: 5px;
      }
    }
  }
  .cor-item:nth-child(4n) {
    margin-right: 0;
  }
  .cor-item:nth-child(n + 1):nth-child(-n + 4) {
    margin-top: 0;
  }
}

.shadow-effect {
  box-shadow: 0px 3px 12px 0px rgba(0, 0, 0, 0.15);
  border-radius: 4px 4px 4px 4px;
}

.chart-container {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  .container-item {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    padding: 20px;
  }
  .wid-50 {
    width: calc(50% - 5px);
  }
  .wid-65 {
    width: calc(65% - 5px);
  }
  .wid-35 {
    width: calc(35% - 5px);
  }
}

.risk-box {
  display: flex;
  align-items: center;
  height: 350px;
  .risk-left {
    width: 45%;
  }
  .risk-right {
    width: 55%;
    border-radius: 4px;
    background-color: rgba(245, 246, 248, 1);
    color: #6C6C6C;
    margin-left: 20px;
    .right-header {
      height: 50px;
      line-height: 50px;
      border-radius: 4px 4px 0px 0px;
      box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.2);
      font-size: 16px;
      font-weight: bold;
      padding: 0 20px;
    }
    .right-content {
      padding: 20px;
      font-size: 14px;
      .title {
        font-weight: bold;
      }
      .text {
        padding: 0 20px;
      }
    }
  }
}

.ability-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 350px;
  .text-box {
    color: #6C6C6C;
    font-size: 14px;
    padding: 10px 30px;
    border-radius: 4px;
    background-color: rgba(245, 246, 248, 1);
    ul {
      padding: 0;
      margin: 0;
    }
  }
}
</style>